#!/bin/sh
CUR_PATH=`dirname $(readlink -f $0)`
InstallPath=/opt/svc-sample
SVC_TYPE=sysv

export PATH=/bin:/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

if [ ! -z "$1" ]; then
    SVC_TYPE=$1
fi

while true; do
    read -p "Confirm to uninstall?(y/n):" choice
    case $choice in
        [yY])
            break;;
        [nN])
            exit;;
        *)
    esac
done

#uninstall service
if [ "sysv" = "${SVC_TYPE}" ]; then
    service svc-sampled stop
    if [ -e /etc/redhat-release ]; then
        chkconfig svc-sampled off
        chkconfig --del svc-sampled
        rm -rf /etc/rc.d/rc0.d/K80svc-sampled
        rm -rf /etc/rc.d/rc1.d/K80svc-sampled
        rm -rf /etc/rc.d/rc2.d/S20svc-sampled
        rm -rf /etc/rc.d/rc3.d/S20svc-sampled
        rm -rf /etc/rc.d/rc4.d/S20svc-sampled
        rm -rf /etc/rc.d/rc5.d/S20svc-sampled
        rm -rf /etc/rc.d/rc6.d/K80svc-sampled
    else
        update-rc.d -f svc-sampled remove
    fi
    rm -rf /etc/init.d/svc-sampled
else
    systemctl stop svc-sample
    systemctl disable svc-sample
    rm -rf "/etc/systemd/system/svc-sample.service"
fi
rm -rf "${InstallPath}"

echo "Uninstall svc-sample success!"

exit 0
